﻿using System.Net;

namespace ToyChat.Client
{
    /// <summary>
    /// Used to describe a connection setup for a client
    /// </summary>
	public class ConnectionSettings : IConnectionSettings
	{
        /// <summary>
        /// Initializes a new (empty) instance of <see cref="ConnectionSettings"/> and sets it's values to the defaults (string.Empty for strings, false for bools, etc.)
        /// </summary>
        public ConnectionSettings()
        {
            this.Nickname = string.Empty;
            this.Password = string.Empty;
            this.Username = string.Empty;
            this.Register = false;
            this.RemoteAddress = IPAddress.None.ToString();
            this.RemotePort = 0;
            this.Email = string.Empty;
        }

        /// <summary>
        /// Gets or Sets the nickname for the connection (The user's nickname on the server)
        /// </summary>
        public string Nickname { get; set; }

        /// <summary>
        /// Gets or Sets the users username for the connection
        /// </summary>
        public string Username { get; set; }

        /// <summary>
        /// Gets or Sets the users password for the connection
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// Gets or Sets the remote port for the connection
        /// </summary>
        public ushort RemotePort { get; set; }

        /// <summary>
        /// Gets or Sets the remote address of the connection
        /// </summary>
        public string RemoteAddress { get; set; }

        /// <summary>
        /// Gets or Sets a value indicating wether or not to attempt registration instead of authentication
        /// </summary>
        public bool Register { get; set; }

        /// <summary>
        /// The user's email address (this need not be set unless <see cref="Register"/> is true)
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// Attempts to validate the settings contained in this instance of <see cref="ConnectionSettings"/>
        /// </summary>
        /// <returns></returns>
        public bool Validate()
        {
            return !string.IsNullOrEmpty(this.Nickname) &&
                !string.IsNullOrEmpty(this.Username) &&
                !string.IsNullOrEmpty(this.RemoteAddress) &&
                this.RemotePort > 0;
        }
    }
}
